﻿using System;

namespace md.imi.membranes.objects
{
    public class LogEntry
    {
        public enum MsgType
        {
            Info,
            Warning,
            Error
        }

        public MsgType MessageType { get; set; }

        public String Message { get; set; }

        public object Sender { get; set; }

        public DateTime TimeStamp { get; set; }

        private static LogEntry PrepareLogEntry(MsgType msgType, object sender, string format, params  object[] values)
        {
            if (format == null)
            {
                return null;
            }

            return new LogEntry()
            {
                MessageType = msgType,
                Message = String.Format(format, values),
                Sender = sender,
                TimeStamp = DateTime.Now
            };
        }

        public static LogEntry Info(object sender, string format, params  object[] values)
        {
            return PrepareLogEntry(MsgType.Info, null, format, values);
        }

        public static LogEntry Warning(object sender, string format, params  object[] values)
        {
            return PrepareLogEntry(MsgType.Warning, null, format, values);
        }

        public static LogEntry Error(string format, params  object[] values)
        {
            return PrepareLogEntry(MsgType.Error, null, format, values);
        }
    }
}